// s2-runner.js

const esm = require("esm");
const requireModule = esm(module);
const _ = require("lodash");

const { readAllValues } = requireModule(
  "../../../awakened-potential/helpers/readAllValues.js"
);
const checkAccuracy = requireModule("../../utils/checkAccuracy.js");
const select32NumbersByS2 = requireModule("./select32NumbersByS2.js");

const allValues = readAllValues("m");
const useWindow = true;
const windowSize = 101;
const predictResults = [];

allValues.forEach((item, index) => {
  const temp = useWindow
    ? allValues.slice(Math.max(0, index - windowSize), index)
    : allValues.slice(0, index);

  if (!temp.length) return;

  const selected = select32NumbersByS2(temp);
  predictResults.push(checkAccuracy(selected, item.number));
});

const total = predictResults.length;
const correct = predictResults.filter((x) => x === 1).length;
const accuracy = total > 0 ? ((correct / total) * 100).toFixed(2) : 0;

let maxWrongStreak = 0;
let currentStreak = 0;
predictResults.forEach((res) => {
  if (res === 0) {
    currentStreak++;
    if (currentStreak > maxWrongStreak) {
      maxWrongStreak = currentStreak;
    }
  } else {
    currentStreak = 0;
  }
});

console.log(`🎯 使用 S2 策略`);
console.log(`预测总数: ${total}`);
console.log(`命中次数: ${correct}`);
console.log(`准确率: ${accuracy}%`);
console.log(`最大连续错误次数: ${maxWrongStreak}`);
